#include <stdio.h>
#include <vector>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  // f[i][j] - count of numbers where length = i and sum of digits = j
  std::vector<std::vector<long long> > f(n + 1, std::vector<long long>(9 * n + 1));
  for (int j = 1; j <= 9; j++) {
    f[1][j] = 1;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= 9 * n; j++) {
      for (int d = 0; d <= 9 && j - d >= 0; d++) {
        f[i][j] += f[i - 1][j - d];
      }
    }
  }
  for (; m > 0; m--) {
    long long k;
    scanf("%I64d", &k);
    int klen = 0, ksum = 0;
    while (k > 0) {
      klen++;
      ksum += k % 10;
      k /= 10;
    }
    long long ans = 0;
    for (int len = klen + 1; len <= n; len++) {
      for (int sum = 1; sum < ksum; sum++) {
        ans += f[len][sum];
      }
    }
    if (ksum > 1) {
      ans++;
    }
    printf("%I64d ", ans);
  }
}
